$(document).ready(function() {
	doctors.init();
	secretarys.init();
	boss.init();
	speciality.init();
	socialhealth.init();
	doctors_erased.init();
	secretarys_erased.init();
	boss_erased.init();
	speciality_erased.init();
	socialhealth_erased.init();
});

//Datatables jack
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
{
    if ( typeof sNewSource != 'undefined' && sNewSource != null )
    {
        oSettings.sAjaxSource = sNewSource;
    }
    this.oApi._fnProcessingDisplay( oSettings, true );
    var that = this;
    var iStart = oSettings._iDisplayStart;
     
    oSettings.fnServerData( oSettings.sAjaxSource, [], function(json) {
        /* Clear the old information from the table */
        that.oApi._fnClearTable( oSettings );
         
        /* Got the data - add it to the table */
        for ( var i=0 ; i<json.aaData.length ; i++ )
        {
            that.oApi._fnAddData( oSettings, json.aaData[i] );
        }
         
        oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
        that.fnDraw();
         
        if ( typeof bStandingRedraw != 'undefined' && bStandingRedraw === true )
        {
            oSettings._iDisplayStart = iStart;
            that.fnDraw( false );
        }
         
        that.oApi._fnProcessingDisplay( oSettings, false );
         
        /* Callback user function - for event handlers etc */
        if ( typeof fnCallback == 'function' && fnCallback != null )
        {
            fnCallback( oSettings );
        }
    }, oSettings );
}

var oTable;

var doctors = {
	init : function() {
		//full datatables
		oTable = $("#lista_doctors").dataTable({
			"bProcessing": true,
       	 	"sAjaxSource": 'http://localhost/clinica/adminmain/getAllDoctorsDt',
       	 	"aoColumnDefs": [ 
       	 		{
        	      "aTargets": [ 8 ],
        	      "mData": "id",
        	      "mRender": function ( data, type, row ) {
        	    	//This function takes care of render the actions column
                  	var htmlAction = '<div class="btn-group pull-right">';
                  	htmlAction += '<a  class="btn btn-mini" onclick="manageSchedules('+data+')" title="Horarios"><i class="icon-calendar"></i></a>';
                  	htmlAction += '<a  class="btn btn-mini" onclick="manageLicense('+data+')" title="Licencias"><i class="icon-time"></i></a>';
                  	htmlAction += '<a  class="btn btn-mini" onclick="modifyDoctor('+data+')" title="Editar"><i class="icon-pencil"></i></a>';
                  	htmlAction += '<a  class="btn btn-mini" onclick="eraseDoctor('+data+')" title="Borrar"><i class="icon-trash"></i></a>';
                  	htmlAction += '</div>';
                  	return htmlAction;
        	      	}
        	    },
        	    {
        	      "aTargets": [ 7 ],
        	      "mData": "socialhealth",
        	      "mRender": function ( data, type, row ) {
                  	var htmlAction = '<select style="width: 112px;">';
                  	for (var i = 0; i < data.length; i++) {
                  		htmlAction += '<option>'+data[i].socialhealth+'</option>';
                  	}
                  	htmlAction += '</select>';
                  	return htmlAction;
        	      	}
        	    },
        	    {
        	      "aTargets": [ 6 ],
        	      "mData": "speciality",
        	      "mRender": function ( data, type, row ) {
                  	var htmlAction = '<select style="width: 125px;">';
                  	for (var i = 0; i < data.length; i++) {
                  		htmlAction += '<option>'+data[i].speciality+'</option>';
                  	}
                  	htmlAction += '</select>';
                  	return htmlAction;
        	      	}
        	    },
        	    {
        	      "aTargets": [ 3 ],
        	      "mData": "dni_type",
        	      "mRender": function ( data, type, row ) {
                  	htmlAction = "";
                  	if (data == "0") {
                  		htmlAction = "LC";
                  	} else if (data == "1") {
                  		htmlAction = "Pasaporte";
                  	} else if (data == "2") {
                  		htmlAction = "DNI";
                  	}
                  	return htmlAction;
        	      	}
        	    },
        	    {
        	      "aTargets": [ 5 ],
        	      "mData": "has_license",
        	      "mRender": function ( data, type, row ) {
                  	htmlAction = "";
                  	if (data == "0") {
                  		htmlAction = "No";
                  	} else if (data == "1") {
                  		htmlAction = "Si";
                  	} 
                  	return htmlAction;
        	      	}
        	    },
        	],
            "aoColumns": [
	      	  { "mDataProp": "name" },
              { "mDataProp": "lastname" },
              { "mDataProp": "birth" },
              { "mDataProp": "dni_type" },
              { "mDataProp": "dni" },
              { "mDataProp": "has_license" },
              { "mDataProp": "speciality" },
              { "mDataProp": "socialhealth" },
              { "mDataProp": "id" }
            ],
            "oLanguage": {
            	"sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningun dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Ultimo",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                }
            }
		});
		//load social health
		$("#new_doctor_btn").click(function() {
			$("#newDoctorForm input").val("");
			$("#speciality").select2("val", "");
			$("#new_doctor_error_holder").text("");
			$("#socialhealth").select2("val", "");
			loadSocialHealthInNewDoctors();
			loadSpecialitiesInNewDoctors();
		});
		//init some global vars
		dateId = 0;
		$("#newDoctorForm").submit(function() {
			if ($("#speciality").select2("val").length == 0) {
				$("#new_doctor_error_holder").text("Necesita ingresar al menos una especialidad.");
				return false;
			}
			$.get("http://localhost/clinica/adminmain/alreadyExistDoctor",$(this).serialize(),function(data) {
				if (data.length > 0) {
					$("#new_doctor_error_holder").text("Ya existe un medico con el numero y tipo de documento ingresado.");
					return false;
				} 
				$.post("http://localhost/clinica/adminmain/insertDoctor",$("#newDoctorForm").serialize(),function() {
					oTable.fnReloadAjax('http://localhost/clinica/adminmain/getAllDoctorsDt');
					$("#modalNewDoctor").modal("hide");
					return false;
				});
			},'json');
			return false;
		});
		$("#modifyDoctorForm").submit(function() {
			if ($("#speciality_modify").select2("val").length == 0) {
				$("#modify_doctor_error_holder").text("Necesita ingresar al menos una especialidad.");
				return false;
			} else {
				$.post("http://localhost/clinica/adminmain/modifyDoctor",$(this).serialize(),function() {
						oTable.fnReloadAjax('http://localhost/clinica/adminmain/getAllDoctorsDt');
						$("#modalModifyDoctor").modal("hide");
						return false;
				});
				return false;
			}
		});
	},
	destroy: function() {
		oTable.fnDestroy();
	}
};

function loadSpecialitiesInNewDoctors() {
	$.get('http://localhost/clinica/adminmain/getAllSpecialities', function(data) {
			$("#speciality").select2({
				multiple : true,
				tags : data
			});
			$("#speciality_modify").select2({
				multiple : true,
				tags : data
			});
		}, 'json');
}

function loadSocialHealthInNewDoctors() {
	$.get('http://localhost/clinica/adminmain/getAllSocialHealth', function(data) {
			$("#socialhealth").select2({
				multiple : true,
				tags : data
			});
			$("#socialhealth_modify").select2({
				multiple : true,
				tags : data
			});
		}, 'json');
}

var oTableErased;

var doctors_erased = {
	init : function() {
		//full datatables
		oTableErased = $("#lista_doctors_erased").dataTable({
			"bProcessing": true,
       	 	"sAjaxSource": 'http://localhost/clinica/adminmain/getAllErasedDoctorsDt',
       	 	"aoColumnDefs": [ 
       	 		{
        	      "aTargets": [ 8 ],
        	      "mData": "id",
        	      "mRender": function ( data, type, row ) {
        	    	//This function takes care of render the actions column
                  	var htmlAction = '<div class="btn-group pull-right">';
                  	htmlAction += '<a  class="btn btn-mini" onclick="removeDoctorFisically('+data+')" title="Borrar de la papelera"><i class="icon-remove"></i></a>';
                  	htmlAction += '<a  class="btn btn-mini" onclick="restoreDoctor('+data+')" title="Restaurar"><i class="icon-wrench"></i></a>';
                  	htmlAction += '</div>';
                  	return htmlAction;
        	      	}
        	    },
        	    {
        	      "aTargets": [ 7 ],
        	      "mData": "socialhealth",
        	      "mRender": function ( data, type, row ) {
                  	var htmlAction = '<select style="width: 112px;">';
                  	for (var i = 0; i < data.length; i++) {
                  		htmlAction += '<option>'+data[i].socialhealth+'</option>';
                  	}
                  	htmlAction += '</select>';
                  	return htmlAction;
        	      	}
        	    },
        	    {
        	      "aTargets": [ 6 ],
        	      "mData": "speciality",
        	      "mRender": function ( data, type, row ) {
                  	var htmlAction = '<select style="width: 125px;">';
                  	for (var i = 0; i < data.length; i++) {
                  		htmlAction += '<option>'+data[i].speciality+'</option>';
                  	}
                  	htmlAction += '</select>';
                  	return htmlAction;
        	      	}
        	    },
        	    {
        	      "aTargets": [ 3 ],
        	      "mData": "dni_type",
        	      "mRender": function ( data, type, row ) {
                  	htmlAction = "";
                  	if (data == "0") {
                  		htmlAction = "LC";
                  	} else if (data == "1") {
                  		htmlAction = "Pasaporte";
                  	} else if (data == "2") {
                  		htmlAction = "DNI";
                  	}
                  	return htmlAction;
        	      	}
        	    },
        	    {
        	      "aTargets": [ 5 ],
        	      "mData": "has_license",
        	      "mRender": function ( data, type, row ) {
                  	htmlAction = "";
                  	if (data == "0") {
                  		htmlAction = "No";
                  	} else if (data == "1") {
                  		htmlAction = "Si";
                  	} 
                  	return htmlAction;
        	      	}
        	    },
        	],
            "aoColumns": [
	      	  { "mDataProp": "name" },
              { "mDataProp": "lastname" },
              { "mDataProp": "birth" },
              { "mDataProp": "dni_type" },
              { "mDataProp": "dni" },
              { "mDataProp": "has_license" },
              { "mDataProp": "speciality" },
              { "mDataProp": "socialhealth" },
              { "mDataProp": "id" }
            ],
            "oLanguage": {
            	"sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningun dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Ultimo",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                }
            }
		});
		//load social health
		$.get('http://localhost/clinica/adminmain/getAllSocialHealth', function(data) {
			$("#socialhealth").select2({
				multiple : true,
				tags : data
			});
			$("#socialhealth_modify").select2({
				multiple : true,
				tags : data
			});
		}, 'json');
		$.get('http://localhost/clinica/adminmain/getAllSpecialities', function(data) {
			$("#speciality").select2({
				multiple : true,
				tags : data
			});
			$("#speciality_modify").select2({
				multiple : true,
				tags : data
			});
		}, 'json');
	},
	destroy: function() {
		oTableErased.fnDestroy();
	}
};

function removeDoctorFisically(id) {
	$.get("http://localhost/clinica/adminmain/isDoctorErasable", {id:id}, function(data) {
		if (data.length > 0) {
			alert("Ud. no puede borrar este medico, porque el mismo tiene turnos asociados. Por favor, primero borre los turnos, en caso de ser necesario.");
		} else {
			var r=confirm("¿Esta seguro de que desea borrar PERMANENTEMENTE a este medico del sistema?");
			if (r==true) {
			  	$.post("http://localhost/clinica/adminmain/removeDoctor",{id:id}, function(data) {
			  		oTable.fnReloadAjax('http://localhost/clinica/adminmain/getAllDoctorsDt');
			  		oTableErased.fnReloadAjax('http://localhost/clinica/adminmain/getAllErasedDoctorsDt');
				});
			}
		}
	},'json');
}

function eraseDoctor(id) {
	var r=confirm("¿Esta seguro de que desea borrar a este medico del sistema?");
	if (r==true) {
	  $.post("http://localhost/clinica/adminmain/eraseDoctor",{id:id}, function(data) {
	  	oTable.fnReloadAjax('http://localhost/clinica/adminmain/getAllDoctorsDt');
	  	oTableErased.fnReloadAjax('http://localhost/clinica/adminmain/getAllErasedDoctorsDt');
	  });
	}
}

function restoreDoctor(id) {
	  $.post("http://localhost/clinica/adminmain/restoreDoctor",{id:id}, function(data) {
	  	oTable.fnReloadAjax('http://localhost/clinica/adminmain/getAllDoctorsDt');
	  	oTableErased.fnReloadAjax('http://localhost/clinica/adminmain/getAllErasedDoctorsDt');
	  });
}

function eraseLicense(id) {
	var r=confirm("¿Esta seguro de que desea borrar a este doctor del sistema?");
	var ids = id;
	if (r==true) {
	  $.post("http://localhost/clinica/adminmain/eraseLicense",{id:ids}, function(data) {
	  	if (!(typeof oTableLicense === 'undefined')) {
	  		$("#license_doctor_error_holder").text("");
	  		oTableLicense.fnReloadAjax('http://localhost/clinica/adminmain/getLicenseForDoctorDt?id='+ids);
	  	}
	  });
	}
}

function eraseSecretary(id2) {
	var r=confirm("¿Esta seguro de que desea borrar a esta/e secretaria/o del sistema?");
	if (r==true) {
	  $.post("http://localhost/clinica/adminmain/eraseSecretary",{id:id2}, function(data) {
	  	oTableSecretaryErased.fnReloadAjax("http://localhost/clinica/adminmain/getAllErasedSecretaryDt");
	  	oTableSecretary.fnReloadAjax("http://localhost/clinica/adminmain/getAllSecretarysDt");
	  });
	}
}

var schedulesCal;

//Magic fella its magic
function addZ(n){return n<10? '0'+n:''+n;}

function cleanSchedulesForm() {
	$("#speciality_schedule").children().remove();
	$("#title_schedule").val("");
	$("#start_schedule").val("");
	$("#until_schedule").val("");
	$("#hidden_schedule").val("");
}

function manageSchedules(id) {
	//Init calendar
	if (typeof schedulesCal == "undefined") {
		createScheduleAdd(id);
	} else {
		$("#calendar").fullCalendar( 'destroy' );
		createScheduleAdd(id);
	}
	$("#scheduleDoctorId").val(id);
	$("#malditamalditamalditamaldita").click(function(){
		$.post('http://localhost/clinica/adminmain/insertSchedule', $("#manageScheduleForm").serialize(), function(data) {
			$("#calendar").fullCalendar( 'refetchEvents' );
		});
	});
	$("#modalManageSchedules").modal('show');
	$('#modalManageSchedules').on('shown', function () {
		$("#calendar").fullCalendar('render');
			$.get("http://localhost/clinica/adminmain/getAllSpecialitiesById?id="+id, function(dataa) {
			cleanSchedulesForm();
			for (var l = 0; l < dataa.length; l++) {
				var htmlOption = "";
				htmlOption += "<option value=\""+dataa[l].id+"\">"+dataa[l].text+"</option>";
				$("#speciality_schedule").append(htmlOption);
			}
		}, 'json');
	});
}

function createScheduleAdd(id) {
	schedulesCal = $("#calendar").fullCalendar({
			height: 300,
			allDaySlot: false,
			axisFormat: "HH:mm:ss",
			events: "http://localhost/clinica/adminmain/getDoctorSchedules?id="+id,
			eventDataTransform: function(data) {
				var start = new Date();
				if (start.getDay()-data.day > 0) {
					start.setHours(start.getHours()-(24*(start.getDay()-data.day )));
				} else {
					start.setHours(start.getHours()+(24*(data.day-start.getDay())));
				}
				var startHour = data.start.split(":")[0];
				var startMinute = data.start.split(":")[1];
				var startSecond = data.start.split(":")[2];
				start.setHours(startHour);
				start.setMinutes(startMinute);
				start.setSeconds(startSecond);
				
				var end = new Date();
				if (end.getDay()-data.day > 0) {
					end.setHours(end.getHours()-(24*(end.getDay()-data.day )));
				} else {
					end.setHours(end.getHours()+(24*(data.day-end.getDay())));
				}
				var endHour = data.end.split(":")[0];
				var endMinute = data.end.split(":")[1];
				var endSecond = data.end.split(":")[2];
				end.setHours(endHour);
				end.setMinutes(endMinute);
				end.setSeconds(endSecond);
				
				var result = {
					id: data.id,
					title: data.title,
					start: start.getFullYear()+"-"+addZ(start.getMonth()+1)+"-"+addZ(start.getDate())+" "+data.start,
					end: end.getFullYear()+"-"+addZ(end.getMonth()+1)+"-"+addZ(end.getDate())+" "+data.end,
					allDay: false,
					editable: true
				}
				return result;
			},
			columnFormat: {
			    month: 'ddd',    // Mon
			    week: 'ddd', // Mon 9/7
			    day: 'ddd'  // Monday 9/7
			},
			weekNumbers: false,
			buttonText: {
			    prev:     '&lsaquo;', // <
			    next:     '&rsaquo;', // >
			    prevYear: '&laquo;',  // <<
			    nextYear: '&raquo;',  // >>
			    today:    'hoy',
			    month:    'mes',
			    week:     'semana',
			    day:      'dia'
			},
			dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'],
			defaultView: 'agendaWeek',
			header: "",
			eventDrop: function(date) {
				$.post("http://localhost/clinica/adminmain/updateSchedule", 
					{id:date.id, start:date.start, end:date.end, title:date.title}, function(data) {
						//Do nothing its already updated
				});
			},
			eventResize: function(date) {
				$.post("http://localhost/clinica/adminmain/updateSchedule", 
					{id:date.id, start:date.start, end:date.end, title:date.title}, function(data) {
						//Do nothing its already updated
				});
			},
			eventRender: function(event, element) {
		        element.find('.fc-event-inner').prepend("<i onclick=\"removeSchedule("+event.id+")\" class=\"icon-remove-sign\"></i>");
		        element.find('.fc-event-time').remove();
		    }
		});
}


function removeSchedule(id) {
	$.post("http://localhost/clinica/adminmain/removeSchedule", {id: id}, function(data) {
		$("#calendar").fullCalendar( 'refetchEvents' );
		$("#calendar").fullCalendar( 'rerenderEvents' );
	});
}

function modifyDoctor(id) {
	$("#modify_doctor_error_holder").text("");
	$.get('http://localhost/clinica/adminmain/getDoctorById', {id : id}, function(data) {
		//Set the data
		$("#idDoctor").val(id);
		$("#speciality_modify").select2("data",data[0].speciality);
		$("#socialhealth_modify").select2("data",data[0].socialhealth);
		$("#name").val(data[0].name);
		$("#lastname").val(data[0].lastname);
		$("#date").val(""+data[0].birth);
		$("#dni").val(data[0].dni);
		if (data[0].dni_type == 0) {
			$("#dni_type").attr("selected","selected");
		} else if (data[0].dni_type == 1) {
			$("#dni_type").attr("selected","selected");
		} else if (data[0].dni_type == 2) {
			$("#dni_type").attr("selected","selected");
		}
		$("#modalModifyDoctor").modal('show');
	}, 'json');
}

var oTableLicense;

function manageLicense(id) {
	$("#license_doctor_error_holder").text("");
	$("#signature_license").val("");
	$("#since_license").val("");
	$("#until_license").val("");
	if (!(typeof oTableLicense === 'undefined')) {
		oTableLicense.fnReloadAjax('http://localhost/clinica/adminmain/getLicenseForDoctorDt?id='+id);
	} else {
		oTableLicense = $("#lista_license").dataTable({
			"bProcessing": true,
       	 	"sAjaxSource": 'http://localhost/clinica/adminmain/getLicenseForDoctorDt?id='+id,
       	 	"aoColumnDefs": [ 
       	 		{
        	      "aTargets": [ 3 ],
        	      "mData": "id",
        	      "mRender": function ( data, type, row ) {
        	    	//This function takes care of render the actions column
                  	var htmlAction = '<div class="btn-group pull-right">';
                  	htmlAction += '<a  class="btn btn-mini" onclick="eraseLicense('+data+')" title="Borrar"><i class="icon-trash"></i></a>';
                  	htmlAction += '</div>';
                  	return htmlAction;
        	      	}
        	    },
        	],
            "aoColumns": [
              { "mDataProp": "reason" },
	      	  { "mDataProp": "since" },
	      	  { "mDataProp": "until" },
              { "mDataProp": "id" }
            ],
            "oLanguage": {
            	"sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningun dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Ultimo",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                }
            }
		});
	}
	$("#form_newlicense").submit(function(){
		strDay = parseInt($("#since_license").val().substring(0,2));
		strMonth = parseInt($("#since_license").val().substring(3,5));
		strYear = parseInt("20"+($("#since_license").val().substring(6,8)));
		since = new Date(strYear,strMonth,strDay);
		strDay = parseInt($("#until_license").val().substring(0,2));
		strMonth = parseInt($("#until_license").val().substring(3,5))+1;
		strYear = parseInt("20"+($("#until_license").val().substring(6,8)));
		until = new Date(strYear,strMonth,strDay);
		if (since > until) {
			$("#license_doctor_error_holder").text("La fecha desde no puede ser mayor que la fecha hasta");
			return false;
		}
		$.get("http://localhost/clinica/adminmain/alreadyHaveLicense",$(this).serialize(),function(data) {
			if (data.length > 0) {
				$("#license_doctor_error_holder").text("Aún existe una licencia en vigencia, espere a que esta expire o borrela.");
				return false;
			} else {
				$.post("http://localhost/clinica/adminmain/inserLicense",$("#form_newlicense").serialize(),function(data) {
					$("#license_doctor_error_holder").text("");
					$("#signature_license").val("");
					$("#since_license").val("");
					$("#until_license").val("");
					$("#collaspe_newlicense").collapse('hide');
					oTableLicense.fnReloadAjax('http://localhost/clinica/adminmain/getLicenseForDoctorDt?id='+id);
					oTable.fnReloadAjax('http://localhost/clinica/adminmain/getAllDoctorsDt');
					return false;
				});
			}
		},'json');
		return false;
	});
	$("#id_doctor").val(id);
	$("#modalLicense").modal('show');
}

var oTableSpeciality;

var speciality = {
	init: function() {
		oTableSpeciality = $("#lista_speciality").dataTable({
			"bProcessing": true,
       	 	"sAjaxSource": 'http://localhost/clinica/adminmain/getAllSpecialitiesDt',
       	 	"aoColumnDefs": [ 
       	 		{
        	      "aTargets": [ 1 ],
        	      "mData": "id",
        	      "mRender": function ( data, type, row ) {
        	    	//This function takes care of render the actions column
                  	var htmlAction = '<div class="btn-group pull-right">';
                  	htmlAction += '<a  class="btn btn-mini" onclick="eraseSpeciality('+data+')" title="Borrar"><i class="icon-trash"></i></a>';
                  	htmlAction += '</div>';
                  	return htmlAction;
        	      	}
        	    },
        	],
            "aoColumns": [
	      	  { "mDataProp": "text" },
              { "mDataProp": "id" }
            ],
            "oLanguage": {
            	"sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningun dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Ultimo",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                }
            }
		});
		$("#newSpecialityForm").submit(function(){
			$.post("http://localhost/clinica/adminmain/inserSpeciality",$(this).serialize(),function(data) {
				oTableSpeciality.fnReloadAjax("http://localhost/clinica/adminmain/getAllSpecialitiesDt");
				loadSpecialitiesInNewDoctors();
				$("#speciality_text").val("");
				return false;
			});
			return false;
		});
	}
};

var oTableSpecialityErased;

var speciality_erased = {
	init: function() {
		oTableSpecialityErased = $("#lista_speciality_erased").dataTable({
			"bProcessing": true,
       	 	"sAjaxSource": 'http://localhost/clinica/adminmain/getAllErasedSpecialitiesDt',
       	 	"aoColumnDefs": [ 
       	 		{
        	      "aTargets": [ 1 ],
        	      "mData": "id",
        	      "mRender": function ( data, type, row ) {
        	    	//This function takes care of render the actions column
                  	var htmlAction = '<div class="btn-group pull-right">';
                  	htmlAction += '<a  class="btn btn-mini" onclick="removeSpecialityFisically('+data+')" title="Borrar de la papelera"><i class="icon-remove"></i></a>';
                  	htmlAction += '<a  class="btn btn-mini" onclick="restoreSpeciality('+data+')" title="Restaurar"><i class="icon-wrench"></i></a>';
                  	htmlAction += '</div>';
                  	return htmlAction;
        	      	}
        	    },
        	],
            "aoColumns": [
	      	  { "mDataProp": "text" },
              { "mDataProp": "id" }
            ],
            "oLanguage": {
            	"sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningun dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Ultimo",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                }
            }
		});
	}
};

function removeSpecialityFisically(id) {
	$.get("http://localhost/clinica/adminmain/isSpecialityErasable", {id:id}, function(data) {
		if (data.length > 0) {
			alert("Ud. no puede borrar esta especialidad, porque la misma tiene turnos asociados o algun medico actualmente ejerce dicha especialidad. Por favor, primero borre los turnos, en caso de ser necesario.");
		} else {
			var r=confirm("¿Esta seguro de que desea borrar PERMANENTEMENTE a esta especialidad del sistema?");
			if (r==true) {
			  	$.post("http://localhost/clinica/adminmain/removeSpeciality",{id:id}, function(data) {
			  		oTableSpeciality.fnReloadAjax("http://localhost/clinica/adminmain/getAllSpecialitiesDt");
					oTableSpecialityErased.fnReloadAjax("http://localhost/clinica/adminmain/getAllErasedSpecialitiesDt");
				});
			}
		}
	},'json');
}

function restoreSpeciality(id) {
	$.post("http://localhost/clinica/adminmain/restoreSpeciality", {id:id}, function(data) {
		oTableSpeciality.fnReloadAjax("http://localhost/clinica/adminmain/getAllSpecialitiesDt");
		oTableSpecialityErased.fnReloadAjax("http://localhost/clinica/adminmain/getAllErasedSpecialitiesDt");
	});
}

function eraseSpeciality(id) {
	$.post("http://localhost/clinica/adminmain/eraseSpeciality", {id:id}, function(data) {
		oTableSpeciality.fnReloadAjax("http://localhost/clinica/adminmain/getAllSpecialitiesDt");
		oTableSpecialityErased.fnReloadAjax("http://localhost/clinica/adminmain/getAllErasedSpecialitiesDt");
	});
}

var oTableHealth;

var socialhealth = {
	init: function() {
		oTableHealth = $("#lista_socialhealth").dataTable({
			"bProcessing": true,
       	 	"sAjaxSource": 'http://localhost/clinica/adminmain/getAllSocialHealthDt',
       	 	"aoColumnDefs": [ 
       	 		{
        	      "aTargets": [ 1 ],
        	      "mData": "id",
        	      "mRender": function ( data, type, row ) {
        	    	//This function takes care of render the actions column
                  	var htmlAction = '<div class="btn-group pull-right">';
                  	htmlAction += '<a  class="btn btn-mini" onclick="eraseSocialhealth('+data+')" title="Borrar"><i class="icon-trash"></i></a>';
                  	htmlAction += '</div>';
                  	return htmlAction;
        	      	}
        	    },
        	],
            "aoColumns": [
	      	  { "mDataProp": "text" },
              { "mDataProp": "id" }
            ],
            "oLanguage": {
            	"sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningun dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Ultimo",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                }
            }
		});
		$("#newSocialhealthForm").submit(function(){
			$.post("http://localhost/clinica/adminmain/inserSocialhealth",$(this).serialize(),function(data) {
				oTableHealth.fnReloadAjax("http://localhost/clinica/adminmain/getAllSocialHealthDt");
				loadSocialHealthInNewDoctors();
				$("#socialhealth_text").val("");
				return false;
			});
			return false;
		});
	}
};

var oTableHealthErased;

var socialhealth_erased = {
	init: function() {
		oTableHealthErased = $("#lista_socialhealth_erased").dataTable({
			"bProcessing": true,
       	 	"sAjaxSource": 'http://localhost/clinica/adminmain/getAllErasedSocialHealthDt',
       	 	"aoColumnDefs": [ 
       	 		{
        	      "aTargets": [ 1 ],
        	      "mData": "id",
        	      "mRender": function ( data, type, row ) {
        	    	//This function takes care of render the actions column
                  	var htmlAction = '<div class="btn-group pull-right">';
                  	htmlAction += '<a  class="btn btn-mini" onclick="removeSocialhealthFisically('+data+')" title="Borrar de la papelera"><i class="icon-remove"></i></a>';
                  	htmlAction += '<a  class="btn btn-mini" onclick="restoreSocialhealth('+data+')" title="Restaurar"><i class="icon-wrench"></i></a>';
                  	htmlAction += '</div>';
                  	return htmlAction;
        	      	}
        	    },
        	],
            "aoColumns": [
	      	  { "mDataProp": "text" },
              { "mDataProp": "id" }
            ],
            "oLanguage": {
            	"sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningun dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Ultimo",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                }
            }
		});
	}
};

function restoreSocialhealth(id) {
	$.post("http://localhost/clinica/adminmain/restoreSocialhealth", {id:id}, function(data) {
		oTableHealth.fnReloadAjax("http://localhost/clinica/adminmain/getAllSocialHealthDt");
		oTableHealthErased.fnReloadAjax("http://localhost/clinica/adminmain/getAllErasedSocialHealthDt");
	});
}

function removeSocialhealthFisically(id2) {
	$.get("http://localhost/clinica/adminmain/isSocialhealthErasable", {id:id2}, function (data) {
		if (data.length > 0) {
			alert("No se puede borrar esta obra social, porque aún existen turnos asociados a ella. Por favor, primero borre los turnos.");
		} else {
			var r=confirm("¿Esta seguro de que desea borrar a esta obra social PERMANENTEMENTE del sistema?");
			if (r==true) {
			  $.post("http://localhost/clinica/adminmain/removeSocialhealth",{id:id2}, function(data) {
			  	oTableHealth.fnReloadAjax("http://localhost/clinica/adminmain/getAllSocialHealthDt");
				oTableHealthErased.fnReloadAjax("http://localhost/clinica/adminmain/getAllErasedSocialHealthDt");
			  });
			}
		}
	},'json')
}

function eraseSocialhealth(id) {
	$.post("http://localhost/clinica/adminmain/eraseSocialhealth", {id:id}, function(data) {
		oTableHealth.fnReloadAjax("http://localhost/clinica/adminmain/getAllSocialHealthDt");
		oTableHealthErased.fnReloadAjax("http://localhost/clinica/adminmain/getAllErasedSocialHealthDt");
	});
}

var oTableSecretary;

var secretarys = {
	init : function() {
		oTableSecretary = $("#lista_secretary").dataTable({
			"bProcessing": true,
       	 	"sAjaxSource": 'http://localhost/clinica/adminmain/getAllSecretarysDt',
       	 	"aoColumnDefs": [ 
       	 		{
        	      "aTargets": [ 4 ],
        	      "mData": "id",
        	      "mRender": function ( data, type, row ) {
        	    	//This function takes care of render the actions column
                  	var htmlAction = '<div class="btn-group pull-right">';
                  	htmlAction += '<a  class="btn btn-mini" onclick="modifySecretary('+data+')" href="#modifyDoctorModal" data-toggle="modal" title="Editar"><i class="icon-pencil"></i></a>';
                  	htmlAction += '<a  class="btn btn-mini" onclick="eraseSecretary('+data+')" title="Borrar"><i class="icon-trash"></i></a>';
                  	htmlAction += '</div>';
                  	return htmlAction;
        	      	}
        	    },
        	],
            "aoColumns": [
	      	  { "mDataProp": "name" },
              { "mDataProp": "lastname" },
              { "mDataProp": "login" },
              { "mDataProp": "password" },
              { "mDataProp": "id" }
            ],
            "oLanguage": {
            	"sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningun dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Ultimo",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                }
            }
		});
		
		$("#new_secretary_btn").click(function() {
			$("#newSecretaryForm input").val("");
			$("#new_secretary_error_holder").text("");
		});
		
		$("#newSecretaryForm").submit(function() {
			$.get("http://localhost/clinica/adminmain/alreadyExistSecretary",$(this).serialize(), function(data) {
				if (data.length > 0) {
					$("#new_secretary_error_holder").text("Ya existe una secretaria con ese nombre de usuario");
					return false;
				} else {
					$.post("http://localhost/clinica/adminmain/insertSecretary", $("#newSecretaryForm").serialize(), function(data) {
						oTableSecretary.fnReloadAjax("http://localhost/clinica/adminmain/getAllSecretarysDt");
						$("#modalNewSecretary").modal("hide");
						return false;
					});
				}
			}, 'json');
			return false;
		});
	},
	destroy: function() {
		oTableSecretary.fnDestroy();
	}
};

var oTableSecretaryErased;

var secretarys_erased = {
	init : function() {
		oTableSecretaryErased = $("#lista_secretary_erased").dataTable({
			"bProcessing": true,
       	 	"sAjaxSource": 'http://localhost/clinica/adminmain/getAllErasedSecretaryDt',
       	 	"aoColumnDefs": [ 
       	 		{
        	      "aTargets": [ 4 ],
        	      "mData": "id",
        	      "mRender": function ( data, type, row ) {
        	    	//This function takes care of render the actions column
                  	var htmlAction = '<div class="btn-group pull-right">';
                  	htmlAction += '<a  class="btn btn-mini" onclick="removeSecretaryFisicaly('+data+')" title="Borrar de la papelera"><i class="icon-remove"></i></a>';
                  	htmlAction += '<a  class="btn btn-mini" onclick="restoreSecretary('+data+')" title="Restaurar"><i class="icon-wrench"></i></a>';
                  	htmlAction += '</div>';
                  	return htmlAction;
        	      	}
        	    },
        	],
            "aoColumns": [
	      	  { "mDataProp": "name" },
              { "mDataProp": "lastname" },
              { "mDataProp": "login" },
              { "mDataProp": "password" },
              { "mDataProp": "id" }
            ],
            "oLanguage": {
            	"sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningun dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Ultimo",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                }
            }
		});
	},
	destroy: function() {
		oTableSecretaryErased.fnDestroy();
	}
};

function removeSecretaryFisicaly(id2) {
	var r=confirm("¿Esta seguro de que desea borrar a esta/e secretaria/o PERMANENTEMENTE del sistema?");
	if (r==true) {
	  $.post("http://localhost/clinica/adminmain/removeSecretary",{id:id2}, function(data) {
	  	oTableSecretaryErased.fnReloadAjax("http://localhost/clinica/adminmain/getAllErasedSecretaryDt");
	  	oTableSecretary.fnReloadAjax("http://localhost/clinica/adminmain/getAllSecretarysDt");
	  });
	}
}

function restoreSecretary(id2) {
	  $.post("http://localhost/clinica/adminmain/restoreSecretary",{id:id2}, function(data) {
	  	oTableSecretaryErased.fnReloadAjax("http://localhost/clinica/adminmain/getAllErasedSecretaryDt");
	  	oTableSecretary.fnReloadAjax("http://localhost/clinica/adminmain/getAllSecretarysDt");
	  });
}

function modifySecretary(id) {
	var ids = id;
	$.get("http://localhost/clinica/adminmain/getSecretaryById?id="+id, function(data) {
		$("#secretary_name").val(data[0].name);
		$("#secretary_lastname").val(data[0].lastname);
		$("#secretary_username").val(data[0].login);
		$("#secretary_password").val(data[0].password);
		$("#secretary_id").val(data[0].id);
		$("#modalModifySecretary").modal("show");
		$("#modifySecretaryForm").submit(function() {
			$.post("http://localhost/clinica/adminmain/modifySecretary", $(this).serialize(), function(data) {
				oTableSecretary.fnReloadAjax("http://localhost/clinica/adminmain/getAllSecretarysDt");
				$("#modalModifySecretary").modal("hide");
				$("#modifySecretaryForm input").val("");
				return false;
			});
			return false;
		});
	}, 'json');
}

var oTableBoss;

var boss = {
	init : function() {
		oTableBoss = $("#lista_boss").dataTable({
			"bProcessing": true,
       	 	"sAjaxSource": 'http://localhost/clinica/adminmain/getAllBossDt',
       	 	"aoColumnDefs": [ 
       	 		{
        	      "aTargets": [ 4 ],
        	      "mData": "id",
        	      "mRender": function ( data, type, row ) {
        	    	//This function takes care of render the actions column
                  	var htmlAction = '<div class="btn-group pull-right">';
                  	htmlAction += '<a  class="btn btn-mini" onclick="modifyBoss('+data+')" href="#modalModifyBoss" data-toggle="modal" title="Editar"><i class="icon-pencil"></i></a>';
                  	htmlAction += '<a  class="btn btn-mini" onclick="eraseBoss('+data+')" title="Borrar"><i class="icon-trash"></i></a>';
                  	htmlAction += '</div>';
                  	return htmlAction;
        	      	}
        	    },
        	],
            "aoColumns": [
	      	  { "mDataProp": "name" },
              { "mDataProp": "lastname" },
              { "mDataProp": "login" },
              { "mDataProp": "password" },
              { "mDataProp": "id" }
            ],
            "oLanguage": {
            	"sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningun dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Ultimo",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                }
            }
		});
		$("#newBossForm").submit(function() {
			$.post("http://localhost/clinica/adminmain/insertBoss", $(this).serialize(), function(data) {
				oTableBoss.fnReloadAjax("http://localhost/clinica/adminmain/getAllBossDt");
				$("#modalNewBoss").modal("hide");
				$("#newBossForm input").val("");
				return false;
			});
			return false;
		});
	},
	destroy: function() {
		oTableBoss.fnDestroy();
	}
};

var oTableBossErased;

var boss_erased = {
	init : function() {
		oTableBossErased = $("#lista_boss_erased").dataTable({
			"bProcessing": true,
       	 	"sAjaxSource": 'http://localhost/clinica/adminmain/getAllErasedBossDt',
       	 	"aoColumnDefs": [ 
       	 		{
        	      "aTargets": [ 4 ],
        	      "mData": "id",
        	      "mRender": function ( data, type, row ) {
        	    	//This function takes care of render the actions column
                  	var htmlAction = '<div class="btn-group pull-right">';
                  	htmlAction += '<a  class="btn btn-mini" onclick="removeBossFisicaly('+data+')" title="Borrar de la papelera"><i class="icon-remove"></i></a>';
                  	htmlAction += '<a  class="btn btn-mini" onclick="restoreBoss('+data+')" title="Restaurar"><i class="icon-wrench"></i></a>';
                  	htmlAction += '</div>';
                  	return htmlAction;
        	      	}
        	    },
        	],
            "aoColumns": [
	      	  { "mDataProp": "name" },
              { "mDataProp": "lastname" },
              { "mDataProp": "login" },
              { "mDataProp": "password" },
              { "mDataProp": "id" }
            ],
            "oLanguage": {
            	"sProcessing":     "Procesando...",
                "sLengthMenu":     "Mostrar _MENU_",
                "sZeroRecords":    "No se encontraron resultados",
                "sEmptyTable":     "Ningun dato disponible en esta tabla",
                "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
                "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
                "sInfoPostFix":    "",
                "sSearch":         "",
                "sUrl":            "",
                "sInfoThousands":  ",",
                "sLoadingRecords": "Cargando...",
                "oPaginate": {
                    "sFirst":    "Primero",
                    "sLast":     "Ultimo",
                    "sNext":     "Siguiente",
                    "sPrevious": "Anterior"
                }
            }
		});
	},
	destroy: function() {
		oTableBossErased.fnDestroy();
	}
};

function removeBossFisicaly(id2) {
	var r=confirm("¿Esta seguro de que desea borrar PERMANENTEMENTE a este jefe de turno del sistema?");
	if (r==true) {
	  $.post("http://localhost/clinica/adminmain/removeBoss",{id:id2}, function(data) {
	  	oTableBoss.fnReloadAjax("http://localhost/clinica/adminmain/getAllBossDt");
	  	oTableBossErased.fnReloadAjax("http://localhost/clinica/adminmain/getAllErasedBossDt");
	  });
	}
}

function restoreBoss(id2) {
	  $.post("http://localhost/clinica/adminmain/restoreBoss",{id:id2}, function(data) {
	  	oTableBoss.fnReloadAjax("http://localhost/clinica/adminmain/getAllBossDt");
	  	oTableBossErased.fnReloadAjax("http://localhost/clinica/adminmain/getAllErasedBossDt");
	  });
}

function eraseBoss(id2) {
	var r=confirm("¿Esta seguro de que desea borrar a este jefe de turno del sistema?");
	if (r==true) {
	  $.post("http://localhost/clinica/adminmain/eraseBoss",{id:id2}, function(data) {
	  	oTableBoss.fnReloadAjax("http://localhost/clinica/adminmain/getAllBossDt");
	  	oTableBossErased.fnReloadAjax("http://localhost/clinica/adminmain/getAllErasedBossDt");
	  });
	}
}

function modifyBoss(id) {
	var ids = id;
	$.get("http://localhost/clinica/adminmain/getBossById?id="+id, function(data) {
		$("#boss_name").val(data[0].name);
		$("#boss_lastname").val(data[0].lastname);
		$("#boss_username").val(data[0].login);
		$("#boss_password").val(data[0].password);
		$("#boss_id").val(data[0].id);
		$("#modalModifyBoss").modal("show");
		$("#modifyBossForm").submit(function() {
			$.post("http://localhost/clinica/adminmain/modifyBoss", $(this).serialize(), function(data) {
				oTableSecretary.fnReloadAjax("http://localhost/clinica/adminmain/getAllBossDt");
				$("#modalModifyBoss").modal("hide");
				$("#modifyBossForm input").val("");
				return false;
			});
			return false;
		});
	}, 'json');
}